﻿using System;

using ApplicationLibrary;
using ApplicationLibrary.SqlConnector;

namespace Fighter.Masters.ModuleData
{
    internal class RegisterModule : ApplicationLibrary.SqlConnector.RegisterModule
    {
        public override string Application()
        {
            return "FGHT";
        }

        public override string Module()
        {
            return "MAST";
        }

        public override int CurrentVersion()
        {
            return 1;
        }

        public override Version DllVersion
        {
            get
            {
                return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            }
        }

        public override void RegisterCountersAndCodes()
        {
            GlobalInfo.AddCounter(Counters.Descriptions.Int(), Properties.Resources.CN_Descriptions);
            GlobalInfo.AddCounter(Counters.Athlete.Int(), Properties.Resources.CN_Athletes);
        }

        public override void AddScrounger(ApplicationLibrary.DBManager.iScrounger frm, NameSpace nameSpace)
        {
            //if (nameSpace.ApplicationPath == "Fighter.Fighter.Masters.Forms.Masters")
            //    frm.ScroungerList.Add()
        }

        public override ApplicationLibrary.Preferences.PreferencePanel[] RegisterPreferences()
        {
            //return new ApplicationLibrary.Preferences.PreferencePanel[]
            //{
            //    new AccountingPreferencePanel()
            //};
            return null;
        }

        protected override bool CreateDBTables()
        {
            SqlCreateTable newTable = new SqlCreateTable(SqlABConnection);

            #region FG_Titles
            if (SearchTable(FG_Titles.Name))
            {
                newTable.NewTable(FG_Titles.Name);

                newTable.AddColumn(FG_Titles.Title);
                newTable.AddColumn(FG_Titles.Description);

                newTable.AddPrimaryKey(FG_Titles.Title);

                newTable.Create();
            }
            #endregion

            #region FG_Descriptions
            if (SearchTable(FG_Descriptions.Name))
            {
                newTable.NewTable(FG_Descriptions.Name);

                newTable.AddColumn(FG_Descriptions.Type);
                newTable.AddColumn(FG_Descriptions.ID);
                newTable.AddColumn(FG_Descriptions.Description);

                newTable.AddPrimaryKey(new iColumn[] { FG_Descriptions.Type, FG_Descriptions.ID });

                newTable.Create();
            }
            #endregion

            #region FG_Club
            if (SearchTable(FG_Club.Name))
            {
                newTable.NewTable(FG_Club.Name);
                newTable.AddColumn(FG_Club.Mail);
                newTable.AddColumn(FG_Club.Club);
                newTable.AddColumn(FG_Club.City);
                newTable.AddColumn(FG_Club.Region);
                newTable.AddColumn(FG_Club.Phone);

                newTable.AddPrimaryKey(FG_Club.Mail);

                newTable.Create();
            }
            #endregion

            #region FG_Coach
            if (SearchTable(FG_Coach.Name))
            {
                newTable.NewTable(FG_Coach.Name);

                newTable.AddColumn(FG_Coach.Mail);
                newTable.AddColumn(FG_Coach.Line);
                newTable.AddColumn(FG_Coach.FirstName);
                newTable.AddColumn(FG_Coach.Phone);

                newTable.AddPrimaryKey(FG_Coach.Mail, FG_Coach.Line);

                newTable.Create();
            }
            #endregion

            #region FG_Athlete
            if (SearchTable(FG_Athlete.Name))
            {
                newTable.NewTable(FG_Athlete.Name);

                newTable.AddColumn(FG_Athlete.Mail);
                newTable.AddColumn(FG_Athlete.ID);
                newTable.AddColumn(FG_Athlete.FirstName);
                newTable.AddColumn(FG_Athlete.Gender);
                newTable.AddColumn(FG_Athlete.BirthDay);
                newTable.AddColumn(FG_Athlete.Weight);
                newTable.AddColumn(FG_Athlete.Belt);
                newTable.AddColumn(FG_Athlete.GrapLevel);
                newTable.AddColumn(FG_Athlete.FContMatch);
                newTable.AddColumn(FG_Athlete.LKickMatch);
                newTable.AddColumn(FG_Athlete.K1RulMatch);

                newTable.AddPrimaryKey(FG_Club.Mail, FG_Athlete.ID);

                newTable.Create();
            }
            #endregion

            return true;
        }

        protected override bool UpdateDBTables()
        {
            //if (dbVersion < 2)
            //{
            //    SqlCreateTable alterMaster = new SqlCreateTable(SqlABConnection);

            //    if (!SearchColumn(FG_Masters.Email))
            //    {
            //        alterMaster.AlterTable(FG_Masters.Name);
            //        alterMaster.AddColumn(FG_Masters.Email);
            //        alterMaster.Alter();
            //    }
            //}

            return true;
        }
    }
}